import scrapy
from datetime import datetime

class ForexItem(scrapy.Item):
    """
    外汇数据项定义
    对应招商银行外汇牌价数据
    """
    # 货币名称
    currency = scrapy.Field()
    # 现汇买入价
    tbp = scrapy.Field()  # Telegraphic Transfer Buying Price
    # 现钞买入价  
    cbp = scrapy.Field()  # Cash Buying Price
    # 现汇卖出价
    tsp = scrapy.Field()  # Telegraphic Transfer Selling Price
    # 现钞卖出价
    csp = scrapy.Field()  # Cash Selling Price
    # 发布时间
    publish_time = scrapy.Field()
    # 爬取时间
    crawl_time = scrapy.Field()
    
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # 自动设置爬取时间
        if 'crawl_time' not in self:
            self['crawl_time'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')